from pynput import keyboard  # 导入键盘类

for n in keyboard.Key:
    print(n)


# 定义按键监听函数
def on_press(key):
    '按下按键时执行。'
    if key == keyboard.Key.up:
        print('special key {0} pressed'.format(key))
# 通过属性判断按键类型。


def on_release(key):
    '松开按键时执行。'
    if key == keyboard.Key.esc:
        # Stop listener
        return False
    else:
        pass


if __name__ == '__main__':
    # Collect events until released
    with keyboard.Listener(
            on_press=on_press,
            on_release=on_release) as listener:
        listener.join()
